<?php

class Sendlog_Controller Extends Controller {

    private $type_object;
	private $sendstate;
	private $arealist;
	private $keeptime;	//保存时间
    function _init() {
        check_level(50, segment(0), segment(1, 'index'));
        $this->arealist=get_area_list_option();
        $this->type_object = get_type_object_db();
        //$this->type_object = get_type_object_id_name();
        $this->sendstate=array(
        		'1'=>'未发送',
        		'2'=>'已发送',
        );
        //$this->load->database('db');
    }

    function index() {
        $this->view->display("push/sendlog/index");
    }

    function flexigrid() {
        //读取flexigrid传输的数据
        list($colkey, $colsinfo, $where, $sortname, $sortorder, $offset, $rp, $page) = $this->common->get_flexigrid_params();

        $rows = array();
        $sql = "SELECT COUNT(id) AS num FROM tmp_token WHERE {$where}";

        $one = $this->db->one($sql);

        $total = $one['num'];
        $orderby = $sortname ? "ORDER BY {$sortname} {$sortorder} " : "ORDER BY id DESC";
        $sql = "SELECT {$colsinfo} FROM tmp_token WHERE {$where} {$orderby} LIMIT {$offset},{$rp}";
        $this->db->query($sql);

        while ($n = $this->db->get_array('default')) {
        	
        	$n['status'] = $this->sendstate[$n['status']]."-".$n['status'];
        	
            $rows[] = array('id' => $n['id'], 'cell' => ($n));
        }
        $result = array(
            'page' => $page,
            'total' => $total,
            'rows' => $rows
        );
        echo json_encode($result);
    }
	
    function del($id) {
    		
    	$c = 0;
    	$r = '';
    
    	if ($this->db->delete('tmp_token', array('id' => $id))) {
    		insert_log(translate('MENU_PUSH_ROLE'),translate('DEL'),array('id'=> $id));
    		$c = 1;
    		$r = translate('C_TIPS_SUCCESS_TEXT');
    
    	} else {
    		$r = translate('C_TIPS_ERROR_TEXT');
    	}
    	json_output($c, $r);
    
    }
    
    function multi() {
    
    	$type = $this->input->post("type");
    	$ids = $this->input->post("ids");
    	$c = 0;
    	$r = '';
    	if (count(explode(',', $ids)) == 0) {
    		$r = translate('C_INVALID_PARAMS');
    	} else {
    		if ($type == 'delete') {
    			$this->db->query("DELETE FROM tmp_token WHERE id IN ({$ids})");
    			$c = 1;
    		} else {
    			$r = translate('C_INVALID_PARAMS');
    		}
    	}
    	json_output($c, $r);
    		
    }

}

?>